import { handleActions } from 'redux-actions'
import { success } from '../ui-components'
import util from '../util'

const init = {
  rewards: {
    teamQuota: 0,
    personalQuota: 0,
  },
  medal: {},
  reawrdsById: {},
  quotaInfo: {
    personalQuota: 0,
    usedPersonalQuota: 0,
    teamQuota: 0,
    usedTeamQuota: 0,
  },
}

export default handleActions({
  'fetch rewards' : (state, { payload }) => ({
    ...state,
    rewards: payload,
  }),
  'fetch medal': (state, { payload }) => ({
    ...state,
    medal: payload,
  }),
  'fetch quota info': (state, { payload }) => ({
    ...state,
    quotaInfo: payload,
  }),
  'fetch rewards by id': (state, { payload }) => ({
    ...state,
    reawrdsById: {
      ...state.reawrdsById,
      [payload.id]: payload.data,
    },
  }),
}, init)
